import subprocess
import sys


def install_requirements(mirror_url=None):
    try:
        if mirror_url:
            subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt", "--index-url", mirror_url])
        else:
            subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
        print("All required modules have been installed successfully.")
    except subprocess.CalledProcessError:
        print("Failed to install required modules.")


if __name__ == "__main__":
    # 可以修改为你想要使用的镜像源，例如国内的阿里云镜像源
    mirror_url = "https://mirrors.aliyun.com/pypi/simple/"
    install_requirements(mirror_url)